<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>激活卡申请审批</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->

  </head>
  <%@ include file="/WEB-INF/jsp/common/common.jsp" %>
  <script src="js/jquery.divbox.js" type="text/javascript"></script>
  <script src="js/getCardPermission.js" type="text/javascript"></script>
  <style>
    .hide {
        display: none;
    }
  	.table_box {
  		width:80%; border-left:1px #bbcddb solid; border-top:1px #bbcddb solid; background-color:#f6f7f9;box-sizing: content-box; margin-left: 10%; margin-top: 20px;
  	}
  	.table_box th{
  		font-family: "宋体"; font-size:12px; color:#343233; text-align:center; line-height:30px; border-bottom:1px #bbcddb solid; border-right:1px #bbcddb solid; background-color:#f6f7f9;
  		}
  	.table_box td{
  		text-align:center; line-height:30px;border-bottom:1px #bbcddb solid;  font-family: "宋体"; font-size:12px; border-right:1px #bbcddb solid; background-color:#f6f7f9;
  	}
  	.table_box input {
  		width: 80%;
  	}
  	.table_box .disabled {
  		background-color: #ccc;
  	}
  	.table_box .textarea_1 {
  		width: 92%; min-height: 50px; margin: 10px auto;
  	}
  	.table_box .unwriteMemoBox {
  		diaplay: none;
  	}
  	#application , #review, #approved, #exportBtn {
  		display: none;
  	}
  </style>
  <script type="text/javascript">
    /* 查询卡申请 */
	function queryApproval(displayPage){
		var cardDefineName= $("#activateCardName").val();
		var startTime = $("#startDate").val();
		var endTime = $("#endDate").val();
		var status = $("#status").val();
		var appDeptno = $("#comCode").val();
		/* 状态选择 start */
		/* switch(status) {
   			case '0':
   				$('#review').css('display', 'inline-block')
   				$('#approved').css('display', 'none')
   				break;
   			case '1':
   				$('#approved').css('display', 'inline-block')
   				$('#review').css('display', 'none')
   				break;
   			default:
   				$('#approved').css('display', 'none')
   				$('#review').css('display', 'none')
   		} */
        /* 状态选择 end */
		query({current:displayPage,size:10,cardDefineName: cardDefineName,startTime: startTime, endTime: endTime, status: status, appDeptno: appDeptno});
	}
    function query(param){
    	var jsonDate;
		if(null != param && null != param.current){
			jsonDate =param;	
		}else{
			jsonDate={current:1,size:10};
		}
		$.openLoading();
	    $.ajax({
			url : "actirationCardApply/queryapplyList",
			type : 'POST',
			async : true,
			dataType:'json',
			data: jsonDate,
			success : function(page) {
				$.closeLoading()
				$.each(page.data,function(index,item){ 
					item.appDate=timestampToTime(item.appDate);
				});
				if($.validate(page))return;
				var radioObj ="<input class='input_fxk' name='radioActivation' type='radio' value=''>";

				// var lastObj ='<input type="button" class="input_button_1" id="searchBtn" value="复核同意" onClick="reviewPassed(this)" />&nbsp;<input type="button" class="input_button_1" id="searchBtn" value="打回" onClick="retrieval(this)" />'

				var fieldNames = "appId@TDH,cardDefineName,unitPp,status@TDH,status?{'0': '待复核'; '1': '待核准'; '2': '复核未通过'; '3': '核准通过'; '4': '核准未通过'},appDeptno,appUserid,appDate,appMemo@TDH,checkUserid,checkMemo@TDH,unwriteUserid,unwriteMemo@TDH,cardnoBegin,cardnoEnd";

				var tableContent = creatTable4(fieldNames, page, radioObj);
				var tableObj = $("#activationTable");
				tableObj.find("tbody").remove();
				tableObj.append(tableContent);
				
				var strPage = creatChannelPage(page.current,6,page.maxPage,"73");
				var pageDIV = $("#activationDIV");
				pageDIV[0].innerHTML="";
				pageDIV.append(strPage);
				bindradio();
			}
		})
    }
    /* 重置 */
    function resetApproval() {
    	$("#activateCardName").val('');
		$("#startDate").val('');
		$("#endDate").val('');
		$("#status").val('');
		$("#comCode").val('');
    }
    /* 新增申请卡模板 */
    function apply() {
    	self.location.href="<%=path%>/actirationCardApply/add";
    }
    /* 单选高亮 */
    function bindradio(){
		$("input[name='radioActivation']").click(function(){
			$("input[name='radioActivation']").parent().parent().removeClass("table_highlighter");
			$(this).parent().parent().addClass("table_highlighter");
			// 根据选中状态按钮隐藏
			var status = $('.table_highlighter').children()[4].innerHTML
			if (status !== '0') {
				$('.reviewBox').css('display', 'none')
			} else {
				$('.reviewBox').css('display', 'inline-block')
			}
			if (status !== '1') {
				$('.approvedBox').css('display', 'none')
			} else {
				$('.approvedBox').css('display', 'inline-block')
			}
	   	});
	}
    /* 获取权限 按钮权限控制 */
    function setBtn(power) {
    	//  data为六位字符串 从左到右 分别代表 '卡申请' '卡复核' '卡核准' '卡延期' '退卡申请' '退卡复核'
    	if (power[0] == '1') {
    		$('#application').css('display', 'inline-block')
    	} 
		if (power[1] == '1') {
    		$('#review').css('display', 'inline-block')
    	}
		if (power[2] == '1') {
    		$('#approved').css('display', 'inline-block')
    		//核准权限能导出excel lfd added 20181009
    		$('#exportBtn').css('display', 'inline-block')
    	}
    }
    /* 获取角色 按钮权限控制 */
    /* function setBtn2(data) {
    	if (data.result==='success') {
    		$('#exportBtn').css('display', 'inline-block')
    	}else{
    		$.message("error", data.message);
    	}
    } */
    /* init */
    $(function() {
    	getPermission(setBtn)// 获取权限 控制按钮
    	// getusercompower(setBtn2)// 获取角色 控制按钮
    	queryApproval(1)
    })
    //------------------------ 核准流程
    /* 复核窗口打开 */
    function openApprovalDiv(flag) {
    	var radio = $("input[name='radioActivation']:checked");
    	if (radio.val()==undefined) {
			$.message("error", "请选择一条记录");
			return 
		}
    	$('#cardDefineName').val($('.table_highlighter').children()[2].innerHTML)
    	$('#unitPp').val($('.table_highlighter').children()[3].innerHTML)
    	$('#appMemo').val($('.table_highlighter').children()[9].innerHTML)
    	// lfd 20181114 ie兼容
    	// 添加点击事件
    	// $('#passed_btn').attr('onclick', 'passed(' + flag + ')')
    	// $('#back_btn').attr('onclick', 'back(' + flag + ')')
    	
     	if (flag === '0') {
    		$('.unwriteMemoBox').css('display', 'none')
    		$('#checkMemo').attr('disabled', false).removeClass('disabled')
    		// lfd 20181114 ie兼容
    		$('.review').show()
    		$('.approve').hide()
    	} else {
    		$('.unwriteMemoBox').css('display', 'table-row')
    		$('#checkMemo').attr('disabled', true).addClass('disabled')
    		$('#checkMemo').val($('.table_highlighter').children()[11].innerHTML)
    		// lfd 20181114 ie兼容
            $('.approve').show()
            $('.review').hide()
    	}
    	
    	$('#approvalDiv').OpenDiv()
    }
    /* 复核窗口关闭 */
    function closeApprovalDiv() {
    	// 清空数据
    	$('#cardDefineName').val('')
    	$('#unitPp').val('')
    	$('#appMemo').val('')
		$('#checkMemo').val('')
		$('#unwriteMemo').val('')
    	closeCurrentDIV('approvalDiv')
    }
    /* 复核核准同意 */
    function passed(flag) {
    	isAgree(flag, '1')
    }
    /* 复核核准打回 */
    function back(flag) {
    	isAgree(flag, '0')
    }
    /* 审核申请（复核，复核通过，复核打回，核准，核准通过，核准打回） */
    function isAgree(auditType, yn) {
    	// 整理数据
    	var applyid = $(".table_highlighter").children()[1].innerHTML
    	var message
    	if (auditType === 0) {
    		message = $('#checkMemo').val()
    	} else {
    		message = $('#unwriteMemo').val()
    	}
    	var params = {auditType: auditType, yn: yn, applyid: applyid, message: message}
    	$.openLoading();
	    $.ajax({
			url : "actirationCardApply/auditapply",
			type : 'POST',
			async : true,
			dataType:'json',
			data: params,
			success : function(data) {
				$.closeLoading();
				if("success"==data.result&&""!=data.message){
					$.message("success", data.message);
					closeApprovalDiv()
					/* $(".table_highlighter").children()[4].innerHTML = status */
					queryApproval($('.page_a_click').html())
		    	}
				if("fail"==data.result){
		    		$.message("error", "系统错误,请联系管理员");
		    	}
				if("error"==data.result&&""!=data.message){
		    		$.message("error", data.message);
		    	}
			}
		})
    }
    //------------------------ 核准流程
    // 统一 关闭  窗口
	function closeCurrentDIV(obj){
		$("#"+obj).CloseDiv();
	}
  //--------------------导出Excel
  function exportExcel(){
	  var radio = $("input[name='radioActivation']:checked");
	  if(radio.val()!=undefined){
		  var status = radio.parent().parent().children(" td:eq("+4+")").html();
		  if(status=="3"){
			  var appId = radio.parent().parent().children(" td:eq("+1+")").html();
			  //window.location.href='<%=basePath%>'+"actirationCardApply/exportExcel?appId="+appId; 
			  window.open('<%=basePath%>'+"actirationCardApply/exportExcel?appId="+appId);
		  }else{
			  $.message("error", "请选择核准通过的激活卡");
		  }
	  }else{
		  $.message("error", "请选择激活卡");  
	  }
	  
  }
	/*转换日期*/
	function timestampToTime(data) {
		if(data!=null){
			  var date = new Date(data); 
		        Y = date.getFullYear() + '-';  
		        M = (date.getMonth()+1 < 10 ? '0'+(date.getMonth()+1) : date.getMonth()+1) + '-';  
		        D = date.getDate() + ' ';  
		        h = date.getHours() + ':';  
		        m = date.getMinutes() + ':';  
		        s = date.getSeconds();  
		        return Y+M+D;  	//年-月-日
		}else{
			return data;
		}
  }
  </script>
  <body>
   <div class="current">
		<table class="current_table_1">
			<tbody>
				<tr class="f2">
		            <td>
		              <img src="./images/current_1.jpg">
		            </td>
		            <td class="current_table_1_td">
		              <img src="images/current_1.png">&nbsp;您现在的位置：&nbsp;
		                <span style=" color:#136bab; ">激活卡管理
		                	<span style="padding:0 5px; font-weight:bold; line-height:28px;">&gt;</span>
		                	激活卡审批
		            	</span>
		            </td>
		            <td><img src="./images/current_3.jpg"></td>
	        	</tr>
			</tbody>
		</table>
	</div>
	<table class="table_02" id="table">
		<tr>
			<td>
				<table class="search_table">
					<tr height="30px">
						<td width="20%" height="30">卡定义名称：
							<input id="activateCardName" type="text" class="input_text" maxlength="30" value="">
						</td>
						<td width="20%" height="30">申请机构：
							<input id="comCode" type="text" class="input_text" maxlength="30" value="">
						</td>
						<td width="20%" height="30">申请时间：
							<input id="startDate" onkeydown="false" onclick="showCalendar('startDate','y-mm-dd');" readonly="readonly" class="input_time" type="text" />
						</td>
						<td width="20%" height="30">至：
							 <input id="endDate" onkeydown="false" onclick="showCalendar('endDate','y-mm-dd');" readonly="readonly" class="input_time" type="text" />
						</td>
						<td width="20%" height="30">状态：
						 	<select class="search_select_1" id="status">
								<option value="">--请选择--</option>
								<option value="0">待复核</option>
								<option value="2">复核未通过</option>
								<option value="1">待核准</option>
								<option value="4">核准未通过</option>
								<option value="3">核准通过</option>
							</select>
						</td>
					</tr>
					<tr height="30px">
						<td height="30px" colspan="4" style="text-align: center;">
							<input type="button" class="input_button_1" id="searchBtn" value="查询" onClick="queryApproval(1)" />
							<input type="button" class="input_button_1" id="reset" value="重置" onClick="resetApproval()" />
						</td>
					</tr>
				</table>
			</td>
		</tr>
		<tr>
			<td>
				<table class="search_table">
					<tr height="30px">
						<td height="30">
							<input type="button" class="input_button_1" id="application" value="申请" onClick="apply()" />
							<span class="reviewBox"><input type="button" class="input_button_1" id="review" value="复核" onClick="openApprovalDiv('0')" /></span>
							<span class="approvedBox"><input type="button" class="input_button_1" id="approved" value="核准" onClick="openApprovalDiv('1')" /></span>
							<input type="button" class="input_button_2" id="exportBtn" value="导出Excel" onClick="exportExcel()" />
						</td>
					</tr>
				</table>
			</td>
		</tr>
		<tr>
			<td>
				<table id="activationTable" class="content_table_1">
					<thead>
						<tr class="f1">
							<th style="width:3%;">选择</th>
							<th style="width:12%;">卡定义名称</th>
							<th style="width:5%;">申请份数</th>
							<th style="width:5%;">状态</th>
							<th style="width:11%;">申请机构</th>
							<th style="width:10%;">申请人</th>
							<th style="width:7%;">申请时间</th>
							<th style="width:7%;">复核人</th>
							<th style="width:7%;">核准人</th>
							<th style="width:8%;">卡单起号</th>
							<th style="width:8%;">卡单止号</th>
						</tr>
					</thead>
					<tbody>
					</tbody>
				</table>
				<div id="activationDIV" class="page"></div>
			</td>
		</tr>
	</table>
	<!-- 复核弹窗 start -->
	<div id="approvalDiv"  style="display:none;width:80%;">
		<div class="table_title_div">
			<table class="table_title" style='width:100%;height:20px;'>
				<tr>
				<td width="10%"></td>
				<td width="80%"></td>
				<td width="10%" align="right"><img src="./images/closedown.gif" alt="关闭"  onclick="closeApprovalDiv()"/></td>
				</tr>
			</table>
		</div>
			<table class="table_box">
			<tbody>
				<tr>
					<th >卡定义名称：</th>
					<td >
						<input id="cardDefineName" name="cardDefineName" type="text" readonly="true" class="input_text disabled" disabled>
					</td>
					<th>申请张数：</th>
					<td>
						<input name="unitPp" id="unitPp" type="text" maxlength="5" readonly="true" class="input_text disabled" disabled>
					</td>
				</tr>
				<tr>
					<th>申请说明：</th>
					<td colspan="3"><textarea name="appMemo" id="appMemo"
							class="textarea_1 disabled"  readonly="true" disabled></textarea></td>
				</tr>
				<tr class="checkMemoBox">
					<th>复核说明：</th>
					<td colspan="3"><textarea name="checkMemo" id="checkMemo"
							class="textarea_1"></textarea></td>
				</tr>
				<tr class="unwriteMemoBox">
					<th>核准说明：</th>
					<td colspan="3"><textarea name="unwriteMemo" id="unwriteMemo"
							class="textarea_1"></textarea></td>
				</tr>
			</tbody>
		</table>
		<div align="center" >
		 	<input class="input_button_3 review hide" id="review_passed_btn" type="button" value="同意" onclick="passed(0)">&nbsp;&nbsp;
	        <input class="input_button_3 review hide" id="review_back_btn" type="button" value="打回" onclick="back(0)">
	        <input class="input_button_3 approve hide" id="approve_passed_btn" type="button" value="同意" onclick="passed(1)">&nbsp;&nbsp;
            <input class="input_button_3 approve hide" id="approve_back_btn" type="button" value="打回" onclick="back(1)">
		</div>
	</div>
	<!-- 复核弹窗 end -->
  </body>
</html>